package com.androidtestwheightm.wtheightm0;

import android.annotation.TargetApi;
import android.icu.text.DecimalFormat;
import android.icu.text.NumberFormat;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/9/15 0015.
 */

public class OtherActivity extends AppCompatActivity {

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.other);
        Bundle bun = this.getIntent().getExtras();
        String sex = bun.getString("sex");
        double height = bun.getDouble("height");
        String st="";
        if (sex.equals("M")) {
            st = "男性";
        } else {
            st = "女性";
        }

        String weight= this.weight(sex,height);
        TextView tv=(TextView)findViewById(R.id.textView4);
        tv.setText("你是一位"+weight+"\n你的身高是"+height+ "公分\n你的标准体重是"+weight+"公斤");

    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    private String fm(double m) {
        NumberFormat nf=new DecimalFormat("0.00");
        String height=nf.format(m);

        return height;
    }
    @RequiresApi(api = Build.VERSION_CODES.N)
    private String weight(String sex, double height){
        String weight="";
        if(sex.equals("M")){
            weight = fm((height - 80) * 0.7);
        }else{
            weight = fm((height - 70) * 0.6);
        }
        return weight;
    }
}







